<?php
class LoginController extends CommonController {
	private $model;

	public function __auto() {
		$this->model = K('User');
	}

	//登陆方法
	public function index() {
		if (IS_POST) {

			if (!$userInfo = $this->model -> login()) {
				$this -> error($this -> model -> error);
			}

			$_SESSION['username'] = $userInfo['username'];
			$_SESSION['uid'] = $userInfo['uid'];
					   //如果选择自动登录则设置cookie，没有选择则不设置
						if(isset($_POST['auto'])){
							setcookie(session_name(),session_id(),time() + 3600 *24 *7, '/');
						}else{
							setcookie(session_name(),session_id(),0,'/');
						}
			$this -> success('登陆成功', U('Index/index'));
		}
		
		$this -> display();
	}
	
	//退出
	public function out(){
		session(NULL);//清除变量，销毁资源。相当于session_unset();session_destroy();
		
		$this->success('退出成功',U('Index/Index/index'));
	}

}
?>